{extend name="public/base"/}
{block name="style"}
<link rel="stylesheet" href="/public/lboyue/m/css/mobiscroll.custom-2.16.1.min.css">
<script type="text/javascript" src="/public/lboyue/m/sitejs/book.js?v=20181123"></script>
<script type="text/javascript">

    $(document).ready(function () {


        $('.moreIco').click(function () {

            if($(this).hasClass('closeIco')){

                $('#header').removeClass('app_headerFixed2');
                $(this).removeClass('closeIco');
                $('.app_header_second').hide();
                $('.app_meskSection').hide();

            }else{

                $('#header').addClass('app_headerFixed2');
                $(this).addClass('closeIco');
                $('.app_header_second').show();
                $('.app_meskSection').show();
            }



        })

        $('body').on('click','.app_meskSection',function () {
            $('.app_header_second').hide();
            $('.app_meskSection').hide();
            $('#header').removeClass('app_headerFixed2');
            $('.moreIco').removeClass('closeIco');
        })
    })

</script>
{/block}
{block name="body"}



<div class="app_goBackToTop"></div>
<div class="app_meskSection"></div>

<div class="container">

    <div class="app_header_section2  app_scrollerHeader" id="header">
        <div class="app_header_detail2">
            <div class="app_header_back"></div>
            <div class="app_header_h1">
                章节目录                <a href="/personal/bookcase"> <i class="shujiaIco"></i></a>
                <i class="moreIco"></i>
            </div>
        </div>
		{include file="public/dropnav" /}
		</div>



    <div class="app_body">
        
    <div class="app_catalog_nav">
        <div class="app_selectPlugIn">
            <div class="incomeList">
			{volist name="chaptertype" id="vo"}
                <li style="display: none;">{$vo.title}</li>
			{/volist}
                
            </div>
        </div>
		{if $orderby=="desc"}
			<div class="app_catalog_nav_more"><a href="/book/chapter/{$id}/asc/">倒序</a></div>
		{else}
			<div class="app_catalog_nav_more"><a href="/book/chapter/{$id}/desc/">正序</a></div>
		{/if}
    </div>

    <div class="app_catalogList">
        <ul id="chapterlist">
           
        </ul>
    </div>

    <div class="app_pageBlock">
        <div class="lis"><span class="prev" onclick="pageskip(1)">上一页</span></div>
        <div class="lis">
            <div class="center">
                <div class="input incomeList">
                                        <li style="display: none;">第1页</li>
                                        <li style="display: none;">第2页</li>
                                        <li style="display: none;">第3页</li>
                                    </div>
            </div>
        </div>
        <div class="lis"><span class="next" onclick="pageskip(2)">下一页</span></div>
    </div>

    <input type="hidden" id="page" value="1" />
        
	{block name="include"}{include file="public:footer" /}{/block}
    </div>
</div>

{/block}
{block name="script"}
    <script type="text/javascript" src="/public/lboyue/m/js/jquery.pin.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/mobiscroll.custom-2.16.1.min.js"></script>
    <script type="text/javascript">
		var bookid ={$id};
		var orderby	="{$orderby?$orderby:"asc"}";
        $(document).ready(function () {
            var fristpagelist = "第1页";
            treelist('.incomeList',fristpagelist,function () {
                //console.log('弹窗完了执行的代码');
            });

            $('.app_catalogList li').bind('click',function () {
                $(".app_catalogList li").removeClass('active');
                $(this).addClass('active');
            })

			pageskip(0,1);
        });

        function treelist($obj,$title,$fun) {
            $($obj).mobiscroll().treelist({
                theme: 'mobiscroll',//样式
                //display: 'bottom',//指定显示模式
                lang: "zh",
                rows: 3,
                placeholder: $title,//空白等待提示
                cancelText: null,
                mode:'scroller',//选择模式
                setText: '确定', //确认按钮名称
                cancelText: '关闭',//取消按钮名籍我
                headerText: function (valueText) {
                    return "请选择您需要的选项";
                },
                onBeforeShow:function(inst){
                    //展示前的事件
                },
                onSelect:function(valueText,inst){
                   var pageindex = valueText*1+1*1;
                   console.log(pageindex);

                   $("#page").val(pageindex);
                    $.ajax({
                        url      : "/book/chapter/ajaxchapter",
                        type     : "GET",
                        dataType : "json",
                        data     : {
                            "bookid" : bookid,
                            "orderby" : orderby,
                            "page" : pageindex,
                        },
                        success  : function (re) {
                            var code = re.code;
                            switch (code)
                            {
                                case 1:
                                    var html = "";
									var chapterdata = re.lists;
									for (var i=0; i < chapterdata.length; i++) {
										html +=' <li>';
										html +='<a href="'+chapterdata[i].link+'/">                        <span class="content">'+chapterdata[i].title+'</span>';
										if (chapterdata[i].isvip==0)
										{
											html +='<span class="tips">免费</span>';
										}else{
											html +='<span class="money"></span>';
										}
										html +='</a></li>';
									}
									$("#chapterlist").html(html);
                                    break;
                                case 3:
                                    malert(re.message, 1200, 4);
                                    break;
                                default:
                                    malert("没有了", 1200, 2);
                                    break;
                            }
                        },
                        error    : function () {
                            malert("服务器开小差了～", 1200, 2);
                            return "";
                        }
                    });
                    //点击确定以后的结果
                    $($obj).prev().val($($obj).find("li").eq(valueText).html());
                    $fun();  //点击后的回调函数
                }
            });
        }

        var pagetotal = "3";
        /**
         * 分页跳转上一页下一页
         * @type {string}
         */
        function pageskip(skiptype,newpageindex=0) {
            var pageindex = $("#page").val();

            var newpageindex = newpageindex?newpageindex:0;
            if (skiptype == 1)
            {
                if (pageindex == "1") {
                    malert("没有上一页了");
                    return "";
                }
                newpageindex = parseInt(pageindex) -1;
            }

            if (skiptype == 2)
            {
                if (pageindex ==  pagetotal)
                {
                    malert("没有下一页了");
                    return "";
                }
                newpageindex = parseInt(pageindex) + 1;
            }

            $.ajax({
                url      : "/book/chapter/ajaxchapter",
                type     : "GET",
                dataType : "json",
                data     : {
                    "bookid" : bookid,
                    "orderby" : orderby,
                    "page" : newpageindex
                },
                success  : function (re) {
                    var code = re.code;
                    switch (code)
                    {
                        case 1:
                            $("#page").val(newpageindex);
							var html = "";
                            var chapterdata = re.lists;
							for (var i=0; i < chapterdata.length; i++) {
								html +=' <li>';
								
								if (chapterdata[i].chaptertype==0)
								{
									html +='<a href="'+chapterdata[i].link+'/">';
									html +='<span class="content">'+chapterdata[i].title+'</span>';
								}else{
									html +='<span class="content">[卷]'+chapterdata[i].title+'</span>';
								
								}

								
								if (chapterdata[i].isvip==0)
								{
									html +='<span class="tips">免费</span>';
								}else{
									html +='<span class="money"></span>';
								}
								if (chapterdata[i].chaptertype==0)
								{
									html +='</a>';
								}

								html +='</li>';
							}
                            $("#chapterlist").html(html);
                            break;
                        case 3:
                            malert(re.msg, 1200, 4);
                            break;
                        default:
                            malert("没有下一页了", 1200, 2);
                            break;
                    }
                },
                error    : function () {
                    malert("服务器开小差了～", 1200, 2);
                    return "";
                }
            });
            var valueText = parseInt(newpageindex) -1 ;
            $('.incomeList').prev().val($('.incomeList').find("li").eq(valueText).html());

        }
    </script>
{/block}


